<template>
  <div class="">banner</div>

  <div v-if="user && user.id">
    <dd>{{ user.username }}</dd>
    <dd>{{ user.email }}</dd>
    <dd>{{ user.sex }}</dd>
  </div>

  <div v-if="user.id">
    <button @click="logoutHandle">注销</button>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'

import { baseURL } from '../api/config'
import { getUserInfo, logout } from '../api/user.model'

const route = useRoute()
let user = ref({})
getUserInfo.send().then((res) => {
  console.log(res)
  if (res) user.value = res
  else user.value = {}
})

function logoutHandle () {
  logout.send().then(async () => {
    await navigateTo(`${baseURL.replace(/\/$/, '')}/login`, { external: true })
  })
}
</script>
<style lang="less" scoped>
</style>
